<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FolderType
 *
 * @author QuangKhoi
 */
class FolderType {
    //put your code here
    public $id;
    public $name;
    
    public function __construct($id) {
        $db = Database::getInstance();
        $result = $db->query("SELECT * FROM foldertypes WHERE id = '$id'");
        if ($result->returnCode == 200) {
            if ($result->dataTable->numOfRow == 1) {
                $rows = $result->dataTable->rows[0];
                $this->id = $rows["id"];
                $this->name = $rows["name"];
            }
            else {
                $controller = new ErrorController(new Error(), new ErrorView(), 
                    "404", "Not found any foldertype with provided id");
                $controller->returnError();
                return NULL;
            }
        }
    }
    
    public static function getFolderType() {
        $db = Database::getInstance();
        $query = "SELECT * FROM foldertypes";
        $result = $db->query($query);
        if ($result->returnCode == 200) {
            if ($result->dataTable->numOfRow > 0) {
                foreach ($result->dataTable->rows as $row) {
                    $id = $row['id'];
                    $name = $row['name'];
                    $typeid = "$typeid$id;";
                    $typename = "$typename$name;";
                }
                return array (
                    'typeid' => $typeid,
                    'typename' => $typename
                );
            } else {
                /* $controller = new ErrorController(new Error(), new ErrorView(), 
                  "404", "Not found any user with provided email");
                  $controller->returnError(); */
                return array (
                    'typeid' => 'undefined',
                    'typename' => 'undefined'
                );
            }
        } else {
            /* $controller = new ErrorController(new Error(), new ErrorView, 
              $result->returnCode, $result->message);
              $controller->returnError(); */
            return array (
                'typeid' => 'undefined',
                'typename' => 'undefined'
            );
        }
    }
}

?>
